<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="年份" prop="planYear">
                <el-date-picker type="year" v-model="queryParams.planYear" format="yyyy" value-format="yyyy"
                    :style="{ width: '100%' }" placeholder="请选择年度" clearable></el-date-picker>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['company:suvey:add']">新增</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table fit v-loading="loading" border :data="dataList">
            <el-table-column label="序号" type="index" align="center" width="55">
                <template slot-scope="scope">
                    <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
                </template>
            </el-table-column>
            <el-table-column label="年度" prop="year" align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column label="评价机构" prop="evaluateName" align="center" :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column label="评价时间" prop="evaluateTime" align="center" :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column label="附件" align="center" width="">
                <template slot-scope="scope">
                    <div>
                        <el-link :href="`${baseUrl + scope.row.attachment}`" :underline="false" target="_blank">
                            <span class="el-icon-document">{{ scope.row.attachment }}</span>
                        </el-link>
                    </div>

                </template>
            </el-table-column>

            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope" v-if="scope.row.roleId !== 1">
                    <!-- <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['company:suvey:info']"
                        @click="handleDetail(scope.row.noticeId)">详情</el-button> -->
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['company:suvey:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['company:suvey:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
        <!-- 添加或修改公司公告对话框 -->
        <el-dialog title="评价" :visible.sync="open" width="800px">
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-row>
                    <el-col :span="16">
                        <el-form-item label="年度" prop="year">
                            <el-date-picker type="year" v-model="form.year" format="yyyy" value-format="yyyy"
                                :style="{ width: '100%' }" placeholder="请选择年度" clearable></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="16">
                        <el-form-item label="评价机构" prop="evaluateName">
                            <el-input v-model="form.evaluateName" placeholder="请输评价机构"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="16">
                        <el-form-item label="评价时间" prop="evaluateTime">
                            <el-date-picker v-model="form.evaluateTime" type="date" placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item label="" prop="attachment">
                        <FileUpload v-model="form.attachment">
                        </FileUpload>
                    </el-form-item>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
  
<script>
import { satisfactionList, satisfactionAdd, satisfactionEdit, satisfactionDel } from "@/api/quality/inAudit.js";
export default {
    name: "Notice",
    dicts: ["sys_normal_disable"],
    data() {
        return {
            dataList: [],
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            form: {
            },
            // 表单校验
            rules: {
                year: [
                    { required: true, message: "年度不能为空", trigger: "blur" },
                ],
                attachment: [
                    { required: true, message: "附件不能为空", trigger: "change" },
                ],
                noticeContent: [
                    { required: true, message: "内容不能为空", trigger: "blur" },
                ],
                evaluateName: [
                    { required: false, message: "评价机构不能为空", trigger: "change" },
                ],
                evaluateTime: [
                    { required: false, message: "评价时间不能为空", trigger: "change" },
                ],
            },
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            baseUrl: this.$VUE_APP_IMG_API,
            rowDetail: {},
            detailOPen: false,
        };
    },
    created() {
        console.log(this.$VUE_APP_IMG_API);
        this.getList();
        if (this.$route.query.id) {
            this.handleDetail(this.$route.query.id);
        }
        if (this.$route.query.add) {
            this.handleAdd();
        }
    },
    methods: {


        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    if (this.form.innerSatisfactionId != undefined) {
                        satisfactionEdit(this.form).then((response) => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        this.form.busType = 2;
                        satisfactionAdd(this.form).then((response) => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },

        /** 修改按钮操作 */
        handleUpdate(row) {
            this.resetForm("form");
            this.form = JSON.parse(JSON.stringify(row));
            console.log(this.form);
            this.open = true;
            this.title = "修改";
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            this.$modal
                .confirm('是否确认删除标题为"' + row.year + '"年度的数据项？')
                .then(function () {
                    return satisfactionDel(row.innerSatisfactionId);
                })
                .then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                })
                .catch(() => { });
        },
        handleAdd() {
            this.resetForm("form");
            (this.form = {
                status: 0,
                noticeType: "1",
            }),
                (this.open = true);
        },
        cancel() {
            this.open = false;
            this.detailOPen = false;
        },
        /** 查询列表 */
        getList() {
            this.loading = true;
            satisfactionList(this.queryParams).then((response) => {
                this.dataList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },

        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = [];
            this.resetForm("queryForm");
            this.handleQuery();
        },
    },
};
</script>
<style lang="scss" scoped>
::v-deep.tox-tinymce-aux {
    z-index: 9999 !important;
}

::v-deep .el-dialog__body {
    img {
        width: 100%;
    }
}
</style>
  